﻿/*
 * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
 */

#ifndef BINFILEMODEL_H
#define BINFILEMODEL_H

#define RRE_UNUSED __attribute__((unused))

#include <QString>
#include <QAbstractTableModel>
#include <QCoreApplication>
#include "BurnToolCommon/StringClass.h"
#include "BurnToolCommon/Global.h"

namespace BurnDlg {

class BinFileModel : public QAbstractTableModel {
    Q_OBJECT
public:
    explicit BinFileModel(QObject *parent = nullptr);
    ~BinFileModel() override;
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    int columnCount(const QModelIndex &parent = QModelIndex()) const override;
    void FetchData(QMap<int, BIN_INFO> mapbinFileInfo);
    void FetchData(QMap<int, bool> mapCheckData);
    void ClearData();
    bool GetCheck(int index) const;
    QMap<int, bool> GetMapCheck();
    QString GetValue(int row, int column) const;
    QMap<int, BIN_INFO> GetBinFileInfoData();
    IMAGE_TYPE GetType(int row) const;
    QMap<int, BIN_INFO> GetMapBinFileInfo();
    void SetEditableCheckbox(bool isEditable);
    bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
protected:
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
    Qt::ItemFlags flags(const QModelIndex &index) const override;
    QVariant headerData(int section, Qt::Orientation orientation,
                        int role = Qt::DisplayRole) const override;
    bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value,
                       int role = Qt::EditRole) override;
    Qt::DropActions supportedDragActions() const override;
    Qt::DropActions supportedDropActions() const override;
    QMimeData *mimeData(const QModelIndexList &indexes) const override;
    bool dropMimeData(const QMimeData *data, Qt::DropAction action, RRE_UNUSED int row,
                      RRE_UNUSED int column, const QModelIndex &parent) override;
private:
    QVariant ShowThisLine(const QModelIndex &index) const;
    QVariant CheckState(const QModelIndex &index) const;
    QVariant ShowIcon(const QModelIndex &index) const;
    bool SetDataCheckState(const QModelIndex &index, const QVariant &value);
    void ClearSource();

private:
    QMap<int, BIN_INFO> mapBinFileInfo;
    QMap<int, bool> mapCheck;
    bool isCheckAble;
    QStringList header /* = {"", tr("Name"), QObject::tr(""), QObject::tr(""),
                            QObject::tr(""), QObject::tr(""), QObject::tr(""),
                                QObject::tr(""), "", ""} */;
    MyStringClass::StringClass stringClass;
};

}
#endif // BINFILEMODEL_H
